package com.github.rexsheng.mybatis.handler;

import com.github.rexsheng.mybatis.config.BuilderConfiguration;
import com.github.rexsheng.mybatis.extension.ColumnQueryBuilder;

/**
 * @author RexSheng
 * 2020年10月16日 上午12:24:09
 * @since 1.6.0
 */
public class MybatisPlusColumnHandler extends DefaultColumnHandler{

	@Override
	public String getName(ColumnQueryBuilder<?> columnBuilder,BuilderConfiguration configuration) {
		if(columnBuilder.getField()!=null) {
            com.baomidou.mybatisplus.annotation.TableField columnName=columnBuilder.getField().getAnnotation(com.baomidou.mybatisplus.annotation.TableField.class);
            if(columnName!=null) {
                return columnName.value();
            }
        }
        return super.getName(columnBuilder, configuration);
	}
	
	@Override
	public Boolean isPrimaryKey(ColumnQueryBuilder<?> columnBuilder, BuilderConfiguration configuration) {
		if(columnBuilder.getField()!=null) {
            com.baomidou.mybatisplus.annotation.TableId columnName=columnBuilder.getField().getAnnotation(com.baomidou.mybatisplus.annotation.TableId.class);
            return columnName!=null;
        }
        return super.isPrimaryKey(columnBuilder, configuration);
	}
}
